FROM ubuntu as source

RUN apt-get update && apt-get -y install git

WORKDIR /app
RUN git clone https://github.com/kkroening/ffmpeg-python.git

FROM python:3.10

COPY *.py /app/
COPY --from=source /app/ffmpeg-python /opt/ffmpeg-python
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list \
    && echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
    && echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
    && echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
    && echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
    && echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
    && echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
    && echo "deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list

RUN apt-get update && apt-get -y install ffmpeg fonts-wqy-zenhei

WORKDIR /app
RUN pip install setuptools>=40.8.0 ffmpeg_python numpy pillow pony virtualvideo websocket-client opencv-python-headless -i https://pypi.tuna.tsinghua.edu.cn/simple

WORKDIR /opt
RUN pip install -e ./ffmpeg-python -i https://pypi.tuna.tsinghua.edu.cn/simple

WORKDIR /app

CMD python main.py